﻿@model OT.Areas.Instructor.Models.Users
@{
    ViewBag.Title = "Index";
    Layout = "~/Areas/Instructor/Views/Shared/_Layout.cshtml";
}

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)
    <div id="divMsgIndex"></div>
    <div class="admin-form" style="margin-top:0px;">
        <div class="container">
            <div class="row">
                <div class="col-lg-12">
                    <!-- Widget starts -->
                    <div class="widget wred">
                        <div class="widget-head">
                            <i class="fa fa-user"></i>User Profile 
                        </div>
                        <div class="widget-content">
                            <div class="padd">
                                <div class="form-horizontal">
                                    <div class="form-group" id="divFirstName">
                                        <label class="control-label col-lg-3" for="name">First Name</label>
                                        <div class="col-lg-9">
                                             @Html.TextBoxFor(model => model.FirstName, new { @maxlength = "50", @class = "form-control" })
                                             @Html.ValidationMessageFor(model => model.FirstName)
                                        </div>
                                    </div>
                                    <div class="form-group" id="divLastName">
                                        <label class="control-label col-lg-3" for="name">Last Name</label>
                                        <div class="col-lg-9">
                                             @Html.TextBoxFor(model => model.LastName, new { @maxlength = "50", @class = "form-control" })
                                             @Html.ValidationMessageFor(model => model.LastName)
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-lg-3" for="name">Address</label>
                                        <div class="col-lg-9">
                                            <textarea class="form-control" placeholder="Enter Address" id="Address" rows="1" maxlength="50">@Model.Address</textarea>
                                            
                                        </div>
                                    </div>
                                    <div class="form-group" >
                                        <label class="control-label col-lg-3" for="name">Email ID</label>
                                        <div class="col-lg-9">
                                             @Html.TextBoxFor(model => model.EmailAddress, new { @maxlength = "50", @class = "form-control", @readonly = true })
                                             @Html.ValidationMessageFor(model => model.EmailAddress)
                                        </div>
                                    </div>
                                    <div class="form-group" id="divMobile">
                                        <label class="control-label col-lg-3" for="name">Mobile No</label>
                                        <div class="col-lg-9">
                                             @Html.TextBoxFor(model => model.MobileNo, new { @maxlength = "50", @class = "form-control" })
                                             @Html.ValidationMessageFor(model => model.MobileNo)
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-lg-3" for="name">Landline No</label>
                                        <div class="col-lg-9">
                                             @Html.TextBoxFor(model => model.LandlineNo, new { @maxlength = "50", @class = "form-control" })
                                             @Html.ValidationMessageFor(model => model.LandlineNo)
                                        </div>
                                    </div>
                                    <div class="form-group" id="divCountry">
                                        <label class="control-label col-lg-3" for="name">Country Name</label>
                                        <div class="col-lg-9">
                                            @Html.DropDownListFor(model => model.CountryID, new SelectList(Model.Countrys, "CountryID", "CountryName"), new { @class = "form-control" })
                                        </div>
                                    </div>
                                    <div class="form-group" id="divState">
                                        <label class="control-label col-lg-3" for="name">State Name</label>
                                        <div class="col-lg-9">
                                             @Html.DropDownListFor(model => model.StateID, new SelectList(Model.States, "StateID", "StateName"), new { @class = "form-control" })
                                        </div>
                                    </div>
                                    <div class="form-group" id="divCity">
                                        <label class="control-label col-lg-3" for="name">City Name</label>
                                        <div class="col-lg-9">
                                                        @Html.DropDownListFor(model => model.CityID, new SelectList(Model.Citys, "CityID", "CityName"), new { @class = "form-control" })
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="widget-foot">
                                 <div class="pull-right">
                                <button class="btn btn-default" type="submit" id="btnCreate" value="Save">Save</button>
                                     </div>
                                <div class="clearfix"></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
}

<script type="text/javascript">
    $(document).ready(function () {
        $('#h2Title').html("<i class='fa fa-user'></i> Profile");
        $('#aTitle').html("Profile");
        $('#liDashboard').addClass("open");
        @*var notice = '@TempData["notice"]';
        if (notice.length > 1) {

            showMsg('divMsgIndex', notice, 'success');
            $('#divMsgIndex').css({ "display": "block" });
        }
        else {
            $('#notice').hide();
        }*@
        $(document).on("change", "#CountryID", null, function (e) {
            var CountryID = $(this).val();
            var sub = $("#StateID").empty();
            sub.append($('<option/>', {
                value: 0,
                text: "----Select State----"
            }))
            var ct = $("#CityID").empty();
            ct.append($('<option/>', {
                value: 0,
                text: "----Select City----"
            }))
            $.getJSON("/Student/Account/LoadState", { CountryID: CountryID },
                   function (classesData) {
                       var select = $("#StateID");
                       select.empty();
                       select.append($('<option/>', {
                           value: 0,
                           text: "----Select State----"
                       }));
                       $.each(classesData, function (index, itemData) {
                           select.append($('<option/>', {
                               value: itemData.Value,
                               text: itemData.Text
                           }));
                       });
                   });
            return false;
        });

        $(document).on("change", "#StateID", null, function (e) {
            var StateID = $(this).val();
            var sub = $("#CityID").empty();
            $.getJSON("/Student/Account/LoadCity", { StateID: StateID },
                   function (classesData) {
                       var select = $("#CityID");
                       select.empty();
                       select.append($('<option/>', {
                           value: 0,
                           text: "----Select City----"
                       }));
                       $.each(classesData, function (index, itemData) {
                           select.append($('<option/>', {
                               value: itemData.Value,
                               text: itemData.Text
                           }));
                       });
                   });
            return false;
        });
        $(document).on("click", "#btnCreate", null, function (e) {
            var FirstName = $("#FirstName").val();
            var LastName = $("#LastName").val();
            var Address = $("#Address").val();
            var MobileNo = $("#MobileNo").val();
            var LandlineNo = $("#LandlineNo").val();
            var CountryID = $("#CountryID").val();
            var StateID = $("#StateID").val();
            var CityID = $("#CityID").val();
            e.preventDefault();
            if (FirstName == '' || LastName == '' || CountryID == 0 || MobileNo == '') {
                showMsg('divMsgIndex', 'Please Enter Value in Required Fields', 'danger');
                (FirstName == '') ? $('#divFirstName').addClass('has-error') : $('#divFirstName').removeClass('has-error');
                (LastName == '') ? $('#divLastName').addClass('has-error') : $('#divLastName').removeClass('has-error');
                (CountryID == 0) ? $('#divCountry').addClass('has-error') : $('#divCountry').removeClass('has-error');
                (MobileNo == '') ? $('#divMobile').addClass('has-error') : $('#divMobile').removeClass('has-error');
                (StateID == 0) ? $('#divState').addClass('has-error') : $('#divState').removeClass('has-error');
                (CityID == 0) ? $('#divCity').addClass('has-error') : $('#divCity').removeClass('has-error');
            }
            else {
                var rl = "/Instructor/Account/Change?FirstName=" + FirstName + "&LastName=" + LastName + "&Address=" + Address + "&MobileNo=" + MobileNo + "&LandlineNo=" + LandlineNo + "&CountryID=" + CountryID + "&StateID=" + StateID + "&CityID=" + CityID
                $.ajax({
                    url: rl,
                    type: "POST",
                    success: function (result) {
                        if (result == "valid") {
                            showMsg('divMsgIndex', 'Successfuly Updated Record !!', 'success');
                        }
                        else {
                            showMsg('divMsgIndex', 'Failed To Update Record !!', 'danger');
                        }
                    },
                    error: function (data) {
                    }
                });
            }
            return false;
        });
    });
</script>